// pages/search/search.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
     caipin:[ 
     ],
     isClassify:false,
    //  isPrice:false,
     classify:[
     ],
    //  AccordingPrice:[
    //  ],
     noClassify:[],
     searchClass:false,
     noprice:[],
     curr:0,
     curr2:0,
     name:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 无搜索条件
    wx.request({
      url: app.globalData.directory + 'api/v2/getNoSearch', //仅为示例，并非真实的接口地址
      data: {
       
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.status == 'ok') {
          console.log('79811', res.data.data);
          that.setData({
            caipin:res.data.data.goods,
            classify:res.data.data.category,
          
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
  
  },
 
  name:function(event){
    var name = event.detail.value;
    this.setData({
      name:name
    })
  },
  classify:function (e) {
     this.setData({
       isClassify:!this.data.isClassify,
     
     })
  },
  
  mvvmClass:function(e) {
    let that = this
    let index = e.currentTarget.dataset.index
    let classify = this.data.classify
    let name = classify[index].cates_name
    that.setData({
      isClassify: !this.data.isClassify,
      noClassify:name,
      curr:index
    })
    that.search()
  },
  
  huigui:function (e) {
     this.setData({
       isClassify: false,
      //  isPrice: false,
     })
  },
  search: function () {
    var that = this;
   
    var category = that.data.classify[that.data.curr].id;
    var name = that.data.name
    
    wx.request({
      url: app.globalData.directory + 'api/v2/getGoodsSearch', //仅为示例，并非真实的接口地址
      data: {
        category: category,
        name: name
      },
      method: "POST",
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.status == 'ok') {
          console.log('22', res.data);
          if(res.data.data == ''){
            wx.showModal({
              title: "提示",
              content: "对不起,暂无此类商品.",
              showCancel: false,
              confirmText: "确定"
            })
          }else{
            that.setData({
              caipin: res.data.data,
            })
          } 
          
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  }

  
})